home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC Magazine Extra 1998 Summer: The Perfect PC
/
PC Magazine Extra - The Perfect PC - Summer 1998 Vol 6 #2.iso
/
dwzdika
/
1504
/
delb4.bat
next >
Wrap
DOS Batch File
|
1995-10-27
|
2KB
|
78 lines
@ECHO OFF
REM DELB4.BAT - delete files before a given date
REM (the name DELB4.BAT is hard-coded; don't change)
IF '%2'=='' GOTO Syntax
IF NOT EXIST %1 GOTO NotExist
FOR %%v IN (%1) DO IF '%%v'=='%1' GOTO NoWildcard
CLS
ECHO DELB4.BAT: Deleting files matching %1 dated before %2
ECHO.
xcopy %1 /I /L /d:%2 nothing > NEWER$$1.$$$
IF ERRORLEVEL 1 GOTO Error
find /v "File(s)" < NEWER$$1.$$$ > NEWER$$2.$$$
FC NEWER$$2.$$$ NUL /LB200 /N | DATE | FIND ": " > EN#ER.BAT
del NEWER$$2.$$$
:: EN#ER.BAT now contains lines of the form
:: "Enter new date (mm-dd-yy): 1: delb4.bat"
:: Each call to EN#ER.BAT invokes ENTER.BAT once,
:: protecting first file and stripping first line
:: from EN#ER.BAT. Now create ENTER.BAT:
ECHO REN EN#ER.BAT EN@ER.BAT>ENTER.BAT
ECHO %%"%% FIND /V " %%4" < EN@ER.BAT > EN#ER.BAT %%"%%>>ENTER.BAT
ECHO DEL EN@ER.BAT>>ENTER.BAT
ECHO SET DidEnter=Yes>>ENTER.BAT
ECHO IF NOT EXIST %%5 SET DidEnter=Err>>ENTER.BAT
ECHO ATTRIB +R %%5>>ENTER.BAT
:Loop
SET DidEnter=
CALL EN#ER.BAT
IF '%DidEnter%'=='Yes' GOTO Loop
IF '%DidEnter%'=='Err' GOTO NotCur
SET DidEnter=
DEL EN?ER.BAT
IF EXIST DELB4.BAT ATTRIB +R DELB4.BAT
ECHO Files to be deleted:
DIR %1 /A-D-R /O-D | Find "-" | Find /v "e"
CHOICE Ok to delete these files
IF ERRORLEVEL 2 GOTO Nope
ECHO Y | DEL %1 > NUL
:Nope
ATTRIB -R %1
IF EXIST DELB4.BAT ATTRIB -R DELB4.BAT
DEL NEWER$$1.$$$
GOTO End
: NoWildcard ========
ECHO %1 does not include any * or ? wildcards
: Syntax ========
ECHO Syntax: DELB4 filespec mm/dd/yy
ECHO where filespec is a wildcard file specification
ECHO in the current directory
GOTO End
: NotExist ========
ECHO Sorry, no files match %1.
GOTO End
: NotCur ========
SET DidEnter=
DEL EN?ER.BAT
DEL NEWER$$1.$$$
ECHO The first parameter to DELB4.BAT should not contain
ECHO path information. DELB4.BAT is meant to work in the
ECHO current directory. The error that happened suggests
ECHO that the first parameter referred to files in some
ECHO other directory.
GOTO End
: Error ========
ECHO Error with XCOPY; probably %2 is a bad date
: End ========